/*
day281
2020.6.4
*/
#include<iostream>
#include<vector>
#include<string> 
using namespace std;

class Solution {
public:
    int findClosest(vector<string>& words, string word1, string word2) {
    	
		vector<int> vec1,vec2;
		for(int i=0;i<words.size();++i)
		{
			if(words[i]==word1)
			{
				vec1.push_back(i);
			}
			else if(words[i]==word2)
			{
				vec2.push_back(i);
			}
		}
		
		int res=INT_MAX;
		int p1=0,p2=0;
		while(p1<vec1.size() && p2<vec2.size())
		{
			int tem=abs(vec1[p1]-vec2[p2]);
			if(tem<res)
			{
				res=tem;
			}
			
			if(vec1[p1]<vec2[p2])
			{
				p1++;
			}
			else
			{
				p2++;
			}
		}
		
		while(p1<vec1.size())
		{
			int tem=abs(vec1[p1]-vec2.back());
			if(tem<res)
			{
				res=tem;
			}
			p1++;
		}
		
		while(p2<vec2.size())
		{
			int tem=abs(vec2[p2]-vec1.back());
			if(tem<res)
			{
				res=tem;
			}
			p2++;
		}
    
		return res;
	}
};


int main()
{
	return 0;
}
